package com.zzuli.dcxt.controller;

import com.zzuli.dcxt.entiy.User;
import com.zzuli.dcxt.service.PagingService;
import com.zzuli.dcxt.utils.Paging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/paging")
public class PagingController {
    @Autowired
    private PagingService pagingService;

    @RequestMapping("/user")
    public String paging(Paging paging, Model model){
        System.out.println(paging);
        int pageIndex = paging.getPageIndex();
        if (pageIndex<=0||paging==null){
            paging.setPageIndex(1);
        }
        if (paging.getPageSize()==0){
            paging.setPageSize(2);
        }
        List<User> userList=pagingService.paging(paging);
        model.addAttribute("userList",userList);
        model.addAttribute("paging",paging);
        return "paging";
    }
}
